import os

from api.login_api import LoginApi

base_dir = os.path.abspath(os.path.dirname(__file__))


# 获取登录的token
class Get_token(object):
    def __init__(self, mobile="13800000002", password="123456"):
        self.mobile = mobile
        self.password = password

    def get_token(self):
        login_token = LoginApi()
        login_data = {
            "mobile": self.mobile,
            "password": self.password
        }
        response = login_token.login_api(login_data=login_data)
        token = response.json()['data']
        headers = {
            "Authorization": "Bearer " + token,
            "Content-Type": "application/json"
        }
        print(headers)
        return headers


# 公共断言方法
def common_assert_login(case, response, status_code, status, success, message):
    case.assertEqual(status_code, response.status_code)
    case.assertEqual(success, response.json()['success'])
    case.assertEqual(status, response.json()['code'])
    case.assertIn(message, response.json()["message"])
